using UnityEditor;
using UnityEngine;

namespace GameDesigner
{
    [CanEditMultipleObjects]
    [CustomEditor(typeof(PlayableStateMachineView))]
    public class PlayableStateMachineViewEditor : AnimatorStateMachineViewEditor
    {
        protected override void OnDrawSelectAnimationClip(StateAction action) { }

        protected override void OnDrawActionPropertyField(StateAction action, SerializedProperty actionProperty)
        {
            var scRect = EditorGUILayout.GetControlRect(hasLabel: true, 18f, EditorStyles.popup);
            EditorGUI.BeginChangeCheck();
            var clipAssetProperty = actionProperty.FindPropertyRelative("clipAsset");
            EditorGUI.ObjectField(scRect, clipAssetProperty, typeof(AnimationClip), new GUIContent("动画剪辑", $"clipAsset -> length:{action.length}"));
            if (EditorGUI.EndChangeCheck())
            {
                if (clipAssetProperty.objectReferenceValue is AnimationClip clip)
                {
                    action.clipName = clip.name;
                    action.length = clip.length;
                    SetDirty(Self);
                }
            }
        }
    }
}